
package com.mi.global.shop.common.utils;

import android.content.Context;
import android.util.DisplayMetrics;
import android.view.WindowManager;


/**
 */
public class ScreenInfo {

    private static final String TAG = ScreenInfo.class.getSimpleName();

    private ScreenInfo() {
    }

    public static class SingletonHolder {
        private static ScreenInfo INSTANCE = new ScreenInfo();
    }

    public static ScreenInfo getInstance() {
        return SingletonHolder.INSTANCE;
    }

    private int screenWidth;
    private int screenHeight;

    private int screenWidthDip;
    private int screenHeightDip;

    // 密度 0.75 / 1.0 / 1.5 / 2.0 / 3.0
    private float screenDensity;
    // 精度 120 / 160 / 240 / 320 / 480
    private int screenDensitydpi;

    public void initialScreenInfo(Context context) {
        DisplayMetrics dm = new DisplayMetrics();
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        wm.getDefaultDisplay().getMetrics(dm);
        screenWidth = dm.widthPixels;
        screenHeight = dm.heightPixels;
        screenDensity = dm.density;
        screenDensitydpi = dm.densityDpi;

        screenWidthDip = (int) (dm.widthPixels / screenDensity + 0.5f);
        screenHeightDip = (int) (dm.heightPixels / screenDensity + 0.5f);


    }

    /**
     * @return 屏幕宽度 单位px
     */
    public int getScreenWidth() {
        return screenWidth;
    }

    /**
     * @return 屏幕高度 单位px
     */
    public int getScreenHigth() {
        return screenHeight;
    }

    /**
     * @return 屏幕密度 单位 0.75 / 1 / 1.5 / 2 / 3
     */
    public float getScreenDensity() {
        return screenDensity;
    }

    /**
     * @return 屏幕精度 120 / 160 / 240 / 360 / 480
     */
    public int getScreenDensitydpi() {
        return screenDensitydpi;
    }

}
